<?php
/**
 * Joomla! 1.5 component NS Pro
 *
 * @version $Id: nspro.php 2009-04-28 01:47:12 svn $
 * @author Christopher Mavros
 * @package Joomla
 * @subpackage NS Pro
 * @license GNU/GPL
 *
 */

// no direct access
defined('_JEXEC') or die('Restricted access');

// Import Joomla! libraries
jimport('joomla.application.component.model');

class NsproModelFieldedit extends JModel {

    function __construct()
    {
        parent::__construct();

        //global $mainframe, $option;
        $mainframe = JFactory::getApplication();
        $option = JRequest::getCmd('option');
        
        include('components/com_nspro/ftypes.php');
        $this->setState('ftypes', $ftypes);

        $array = JRequest::getVar('cid',  0, '', 'array');
        $this->setId((int)$array[0]);
    }

    function setId($id)
    {
        // Set id and wipe data
        $this->_id      = $id;
        $this->_data    = null;
    }

    function getField()
    {
        $db =& JFactory::getDBO();
        // Load the data
        if (empty( $this->_data )) {
            $query = ' SELECT * FROM `#__nspro_fields` '.
                    '  WHERE `id` = '.$this->_id;
            $db->setQuery( $query );
            $this->_data = $db->loadObject();
        }
        if (!$this->_data) {
            $this->_data = new stdClass();
            $this->_data->id = 0;
            $this->_data->name  = null;
            $this->_data->fieldtype = 0;
            $this->_data->regexp = '';
            $this->_data->required = false;
            $this->_data->published = false;
            $this->_data->show_backend = false;
            $this->_data->abovepos = false;
            $this->_data->ordering = null;
            $this->_data->value = null;
            $this->_data->notes = null;
        }
        return $this->_data;
    }

    function getFields($limit, $limitstart) {
        $db =& JFactory::getDBO();

        $query = 'SELECT * FROM `#__nspro_fields` ORDER BY `id`';

        $fields = $this->_getList( $query , $limitstart, $limit);

        return $fields;
    }

    function getFieldCount() {
        $db =& JFactory::getDBO();

        $query = 'SELECT COUNT(`id`) FROM `#__nspro_fields`';

        $db->setQuery( $query );
        $fCount = $db->loadResult();

        return $fCount;
    }
}
?>